package com.globalresources.business.impl;

import java.util.ArrayList;
import java.util.List;
import com.globalresources.business.inface.IUserService;
import com.globalresources.commons.StringHelper;
import com.globalresources.dao.inface.IUserDao;
import com.globalresources.po.Document;
import com.globalresources.po.User;

/**
 * @author aaron.lu(luzhiyuan) E-mail:atyuan.lu@gmail.com
 * @since 创建时间：Jul 16, 2009 12:49:25 AM
 */
public class UserServiceImpl implements IUserService {
	
	private IUserDao userDaoExtendGenericDao;
	private IUserDao userDaoExtendHibernateDaoSupport;

	
	public IUserDao getUserDaoExtendGenericDao() {
		return userDaoExtendGenericDao;
	}

	public void setUserDaoExtendGenericDao(IUserDao userDaoExtendGenericDao) {
		this.userDaoExtendGenericDao = userDaoExtendGenericDao;
	}

	public IUserDao getUserDaoExtendHibernateDaoSupport() {
		return userDaoExtendHibernateDaoSupport;
	}

	public void setUserDaoExtendHibernateDaoSupport(IUserDao userDaoExtendHibernateDaoSupport) {
		this.userDaoExtendHibernateDaoSupport = userDaoExtendHibernateDaoSupport;
	}

	/**
	 * load user by like username
	*@author aaron.lu(luzhiyuan)
	*@param username
	*@return
	 */
	public List<User> getUsers(String username){
		if (StringHelper.isNotEmpty(username)) {
			username = "%" + username + "%";
		}
		return userDaoExtendGenericDao.getUsers(username);
	}
	
	/**
	 * count users
	*@author aaron.lu(luzhiyuan)
	*@param username
	*@return
	 */
	public int countUsers(String username){
		if (StringHelper.isNotEmpty(username)) {
			username = "%" + username + "%";
		}
		return userDaoExtendGenericDao.countUsers(username);
	}
	
	/**
	 * get User By username
	*@author aaron.lu(luzhiyuan)
	*@param username
	*@return
	 */
	public List<User> getUser(String username){
		return userDaoExtendGenericDao.getUser(username);
	}
	
	/**
	 *Save User
	*@author songduanlei@gmail.com
	*@param user
	*@return
	 */
	public void saveUser(User user){
		userDaoExtendGenericDao.saveUser(user);
	}
	/**
	 *get User by Id
	*@author songduanlei@gmail.com
	*@param user
	*@return
	 */
	public User getUserById(String id){
		return userDaoExtendHibernateDaoSupport.getUserById(id);
	}
	
	
	/**
	 * Save OR Update User
	*@author songduanlei@gmail.com
	*@param user
	*@return
	 */
	public void saveOrUpdateUser(User user){
		userDaoExtendHibernateDaoSupport.saveOrUpdateUser(user);
	}
	
	/**
	 * <P>查询用户
	*@author aaron.lu(luzhiyuan)
	*@param params
	*@return
	 */
	public List<User> getUsers(String[] params){
		List<User> result = new ArrayList<User>();
		if (null != params && params.length > 0) {
			result = userDaoExtendGenericDao.getUsers(params);
		}
		return result;
	}
}
